/*
 * @Author: 0x9DEFA478
 * @Date: 2021-09-16 18:51:20
 * @LastEditTime: 2021-09-16 21:04:19
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#ifndef __I_W25Q_DualBank_H_
#define __I_W25Q_DualBank_H_



#define vI_W25Q_ID_128                                             0xEF17U
#define vI_W25Q_ID_64                                              0xEF16U
#define vI_W25Q_ID_32                                              0xEF15U
#define vI_W25Q_ID_16                                              0xEF14U
#define vI_W25Q_ID_80                                              0xEF13U



//状态掩码
//S0~S7
#define vI_W25Q_Status_BUSY                                        0x01U
#define vI_W25Q_Status_WEL                                         0x02U
#define vI_W25Q_Status_BP0                                         0x04U
#define vI_W25Q_Status_BP1                                         0x08U
#define vI_W25Q_Status_BP2                                         0x10U
#define vI_W25Q_Status_TB                                          0x20U
#define vI_W25Q_Status_SEC                                         0x40U
//#define vI_W25Q_Status_                                         0x80U

//S8~S15
#define vI_W25Q_Status_SRL                                         0x01U
#define vI_W25Q_Status_QE                                          0x02U
//#define vI_W25Q_Status_                                         0x04U
#define vI_W25Q_Status_LB1                                         0x08U
#define vI_W25Q_Status_LB2                                         0x10U
#define vI_W25Q_Status_LB3                                         0x20U
#define vI_W25Q_Status_CMP                                         0x40U
#define vI_W25Q_Status_SUS                                         0x80U

//S16~S24
//#define vI_W25Q_Status_                                         0x01U
//#define vI_W25Q_Status_                                         0x02U
#define vI_W25Q_Status_WPS                                         0x04U
//#define vI_W25Q_Status_                                         0x08U
//#define vI_W25Q_Status_                                         0x10U
#define vI_W25Q_Status_DRV2                                        0x20U
#define vI_W25Q_Status_DRV1                                        0x40U
//#define vI_W25Q_Status_                                         0x80U



#define vI_W25Q_CMD_StatusREGWriteEnable                            0x50U

#define vI_W25Q_CMD_ReadREG_Status1                                 0x05U
#define vI_W25Q_CMD_WriteREG_Status1                                0x01U

#define vI_W25Q_CMD_ReadREG_Status2                                 0x35U
#define vI_W25Q_CMD_WriteREG_Status2                                0x31U

#define vI_W25Q_CMD_ReadREG_Status3                                 0x15U
#define vI_W25Q_CMD_WriteREG_Status3                                0x11U


#define vI_W25Q_CMD_WriteEnable                                     0x06U
#define vI_W25Q_CMD_WriteDisable                                    0x04U

#define vI_W25Q_CMD_ReadData                                        0x03U
#define vI_W25Q_CMD_FastReadData                                    0x0BU
#define vI_W25Q_CMD_FastReadDualOutput                              0x3BU
#define vI_W25Q_CMD_FastReadDual_IO                                 0xBBU
#define vI_W25Q_CMD_FastReadQuadOutput                              0x6BU
#define vI_W25Q_CMD_FastReadQuad_IO                                 0xEBU

#define vI_W25Q_CMD_PageProgram                                     0x02U
#define vI_W25Q_CMD_QuadPageProgram                                 0x32U

#define vI_W25Q_CMD_SectorErase                                     0x20U //4096字节擦除 4096字节对齐
#define vI_W25Q_CMD_32KBErase                                       0x52U //32字节擦除
#define vI_W25Q_CMD_64KBErase                                       0xD8U //64字节擦除
#define vI_W25Q_CMD_ChipErase                                       0xC7U //全片擦除

#define vI_W25Q_CMD_GetID                                           0x90U //获取id





//初始化W25Q_DualBank的IO
void I_W25Q_DualBank_Init(void);

//获取ID
unsigned int I_W25Q_DualBank_GetID(void);


//读取状态寄存器1
unsigned short I_W25Q_DualBank_GetStatusReg1(void);

//读取状态寄存器2
unsigned short I_W25Q_DualBank_GetStatusReg2(void);

//读取状态寄存器3
unsigned short I_W25Q_DualBank_GetStatusReg3(void);

void I_W25Q_DualBank_WaitBusy(void);

//获取容量
void I_W25Q_DualBank_GetSize(unsigned int *Size1,unsigned int *Size2);

//写状态寄存器
void I_W25Q_DualBank_SetStatusReg1(unsigned short value);
//写状态寄存器
void I_W25Q_DualBank_SetStatusReg2(unsigned short value);
//写状态寄存器
void I_W25Q_DualBank_SetStatusReg3(unsigned short value);

//状态寄存器写使能
void I_W25Q_DualBank_RegWriteEnable(void);

//写使能
void I_W25Q_DualBank_WriteEnable(void);


//设置为quad模式
void I_W25Q_DualBank_SetQuad(void);


//=======================================================================================================
//读写操作
//=======================================================================================================


//读数据 FastRead
void I_W25Q_DualBank_ReadData(unsigned int W25qADDR,unsigned char *dst,int Len);

//读数据 可以不2字节对齐
void I_W25Q_DualBank_ReadData_noAlign(unsigned int W25qADDR,unsigned char *dst,int Len);


//写数据
void I_W25Q_DualBank_PageProgram(unsigned int W25qADDR,unsigned char *src,int Len);


//擦除 8192字节
void I_W25Q_DualBank_Erase(unsigned int W25qADDR);

//擦除 64*1024字节
void I_W25Q_DualBank_64KBErase(unsigned int W25qADDR);

//擦除 128*1024字节
void I_W25Q_DualBank_128KBErase(unsigned int W25qADDR);

//全片擦除
void I_W25Q_DualBank_ChipErase(void);


#endif //__I_W25Q_DualBank_H_
